#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<sstream>
#include<assert.h>
#include<cmath>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
const int inf=1000000000;
const double pi=acos(-1.0);
#define eps (1e-15)
#define L ((nod)<<1)
#define R ((nod)<<1|1)
#define lson nod<<1,l,mid
#define rson nod<<1|1,mid+1,r
#define clr(x,a) memset(x,a,sizeof(x))
#define see(x)(cerr<<"[line:"<<__LINE__<<" "<<#x<<" "<<x<<endl)
#define se(x) cerr<<x<<" "
#define sz(x) (int)x.size()
#define pb push_back
template<class T>void show(T a, int n){for(int i=0; i<n; ++i) cout<<a[i]<<' '; cout<<endl;}
template<class T>void show(T a, int r, int l){for(int i=0; i<r; ++i)show(a[i],l);cout<<endl;}

inline int to_i(const string& s)
{int n;sscanf(s.c_str(),"%d",&n);return n;}
inline string to_s(int n)
{char buf[32];sprintf(buf,"%d",n);return string(buf);}
inline int rd(){int x;scanf("%d",&x);return x;}

#define maxn    80000
const int maxe =80000;
int first[maxn];
int E[maxe],C[maxe],next[maxe],M;
void init()
{
	M=-1;
	clr(first,-1);
}
void _ins(int a,int b,int c)
{
	M++;
	next[M]=first[a];
	first[a]=M;
	E[M]=b;
	C[M]=c;
}
void ins(int a,int b,int c)
{
	_ins(a,b,c);
	_ins(b,a,c);
}
int n,m,cas;
int dep[maxn],vis[maxn];
int p,q;
void dfs(int u)
{
	int e,i,j,v;
	vis[u]=cas;
	for(e=first[u]; e!=-1; e=next[e])
	if(vis[v=E[e]]<cas)
	{
		dep[v]=dep[u]+1;
		dfs(v);
	}	
	if(dep[u]>dep[q])	
		q=u;
	if(dep[u]==(dep[q]/2+1))
		p=u;
}
int ans=0,cnt;
int a[maxn];
int b[maxn];
void merge(int u)
{
	vis[u]=cas;
	int i,j,e,k,s=cnt,t=cnt+1,v;
	a[cnt++]=0;
	
	for(e=first[u]; e!=-1; e=next[e])
	if(vis[v=E[e]]<cas)
	{
		merge(v);
		for(i=t; i<cnt; i++)
			a[i]+=C[e];
		j=cnt-1;
		for(i=s; i<t && j>=t; i++)
		if(a[i]+a[j]<=m)
		{
			ans+=(j-t+1);
		}
		else 
		{
			i-=1;
			j--;
		}
		i=s;j=t;k=0;
		for(; i<t && j<cnt;)
		{
			if(a[i]<a[j])
				b[k++]=a[i++];
			else
				b[k++]=a[j++];
		}
		while(i<t) b[k++]=a[i++];
		while(j<cnt) b[k++]=a[j++];
		
		for(i=s,k=0; i<cnt; i++,k++)
			a[i]=b[k];
		t=cnt;
	}
}
int main()
{
	//freopen("in","r",stdin);
	//freopen("out","w",stdout);
    int i,j,k,t;
	while(scanf("%d%d",&n,&m),n||m)
	{
		int cnt=1,x,y,z;
		init();
		for(i=1; i<n;i++)
		{
			x=rd(); y=rd(); z=rd();
			ins(x,y,z);
		}
		clr(dep,0);
		dep[1]=1;
		p=1;
		ans=0;
		cas++;
		dfs(1);
		cas++;
		dep[q]=1;
		dfs(q);
		cas++;
		//cout<<p<<endl;
		merge(p);
		printf("%d\n",ans);
	}
}
